% fname: routing_oddeven__sel_random__topology_8x8__.m
% ./noxim -routing oddeven -sel random -dimx 8 -dimy 8  -sim 10000 -warmup 2000 -size 8 8 -buffer 2 -hs 6 0.2 -hs 7 0.2 -hs 14 0.2 -hs 15 0.2 

function [max_pir, max_throughput, min_delay] = routing_oddeven__sel_random__topology_8x8__(symbol)

data = [
%             pir      avg_delay     throughput      max_delay       rpackets         rflits
           0.0015        20.9378      0.0128093            112            756           6046
           0.0015        18.7078      0.0125668             80            729           5831
           0.0015        19.8058      0.0125172             86            726           5808
           0.0015        20.0839      0.0131732             88            751           6007
           0.0015        19.4562      0.0118214            109            662           5296
           0.0015        19.3439      0.0128263            109            756           6054
           0.0015        20.6913      0.0130881             82            797           6387
           0.0015        21.1372      0.0126794            129            787           6289
           0.0015        22.9877      0.0131754            122            815           6535
           0.0015        22.4752      0.0146932            117            808           6465
           0.0015        18.9192      0.0121792             77            730           5846
           0.0015        21.6604        0.01325            104            795           6360
           0.0015        21.0387      0.0133599            108            775           6199
           0.0015        20.8051      0.0138487            126            790           6315
           0.0015        19.6538      0.0125167             99            751           6008
           0.0015        20.2451      0.0133103            116            771           6176
           0.0015        20.5845      0.0124458             83            746           5974
           0.0015         22.513      0.0136695            129            807           6452
           0.0015        19.8403      0.0137634             96            770           6166
           0.0015        20.9212      0.0126907             96            749           5990
           0.0017        21.9871      0.0144386            133            852           6815
           0.0017        22.2151      0.0140887            103            874           6988
           0.0017        21.4563      0.0145862            113            846           6768
           0.0017        22.1015      0.0149332            115            867           6929
           0.0017        24.8413      0.0149395            157            926           7410
           0.0017        23.0536      0.0145337            145            915           7325
           0.0017        21.5421      0.0135813             96            856           6845
           0.0017        27.0405       0.014754            243            914           7318
           0.0017        23.2416      0.0144167            158            865           6920
           0.0017           19.6      0.0153556             75            890           7125
           0.0017        21.4469      0.0148299            100            904           7237
           0.0017        21.9921      0.0147854             90            888           7097
           0.0017         19.759      0.0132746             79            809           6478
           0.0017        21.2392      0.0142278            100            882           7057
           0.0017        23.2942      0.0138649            122            860           6877
           0.0017        23.5029      0.0142172            113            867           6938
           0.0017        22.0977      0.0145805             97            860           6882
           0.0017        23.6734      0.0148583            141            891           7132
           0.0017        21.0152      0.0143042             84            858           6866
           0.0017        22.8403      0.0140697            124            858           6866
           0.0019        24.9394      0.0165129            158            957           7662
           0.0019         27.004      0.0163266            210           1012           8098
           0.0019        26.7155      0.0171687            198           1030           8241
           0.0019        23.1766      0.0165363            105           1025           8202
           0.0019        24.0408      0.0156598            193            956           7642
           0.0019        22.3397      0.0153689            127            939           7500
           0.0019        22.7223      0.0160323            163            994           7952
           0.0019        24.6239      0.0153569            161            952           7617
           0.0019        23.2518      0.0165593            127            977           7816
           0.0019        24.4382      0.0156311            155            954           7628
           0.0019        24.1356      0.0163354            166            981           7841
           0.0019        23.3462      0.0150423            116            933           7461
           0.0019        25.0326      0.0153468            119            952           7612
           0.0019        22.8995      0.0156996            124            975           7787
           0.0019        26.0495      0.0153206            205            949           7599
           0.0019        24.5446      0.0163525            148            997           7980
           0.0019        24.1356      0.0153373            166            966           7730
           0.0019        22.7184      0.0163417            118            980           7844
           0.0019         25.353      0.0172354            297           1034           8273
           0.0019        26.3786      0.0161488            186           1017           8139
           0.0021        24.8847      0.0166429            210           1049           8388
           0.0021        25.6535      0.0168472            186           1062           8491
           0.0021        30.8214      0.0170437            291           1075           8590
           0.0021         27.465      0.0185061            263           1127           9031
           0.0021          24.64      0.0163848            194           1050           8389
           0.0021        27.5311      0.0171032            192           1077           8620
           0.0021        24.3583      0.0166048            151           1030           8236
           0.0021        26.3573      0.0171806            199           1083           8659
           0.0021        27.0678      0.0178811            255           1091           8726
           0.0021        26.5081      0.0183115            148           1116           8936
           0.0021        27.2853      0.0176979            159           1062           8495
           0.0021        26.8915       0.017248            244           1069           8555
           0.0021        28.6202      0.0177639            180           1119           8953
           0.0021        25.9631      0.0174919            138           1084           8676
           0.0021        26.9038         0.0165            198           1039           8316
           0.0021        24.2581      0.0167381            128           1054           8436
           0.0021        29.8283      0.0183197            232           1118           8940
           0.0021        28.7369       0.017244            282           1068           8553
           0.0021        25.9906      0.0171431            172           1063           8503
           0.0021        34.6078      0.0173125            303           1109           8864
           0.0023        30.0929      0.0186947            238           1141           9123
           0.0023        30.0426      0.0193849            197           1221           9770
           0.0023        27.1591      0.0182659            242           1150           9206
           0.0023        28.3495      0.0195524            231           1213           9698
           0.0023        27.5505      0.0182421            236           1148           9194
           0.0023        36.3597      0.0191543            583           1226           9807
           0.0023        30.3575      0.0190307            244           1161           9287
           0.0023        29.1128      0.0182754            219           1170           9357
           0.0023        32.2398      0.0192129            283           1230           9837
           0.0023        31.4768      0.0184782            302           1164           9313
           0.0023        26.9477      0.0172877            239           1090           8713
           0.0023        30.7523      0.0192339            197           1191           9540
           0.0023        31.8519      0.0191875            286           1229           9824
           0.0023        32.2827      0.0188274            195           1185           9489
           0.0023        30.3137      0.0189563            208           1138           9099
           0.0023        25.7378      0.0182956            181           1152           9221
           0.0023        28.7533      0.0195343            211           1212           9689
           0.0023        37.8473      0.0195371            273           1251          10003
           0.0023        26.6878      0.0182871            284           1169           9363
           0.0023        37.2483      0.0190615            473           1200           9607
           0.0025        30.4502      0.0194531            181           1246           9960
           0.0025        30.9961      0.0204899            161           1269          10163
           0.0025        27.8769       0.018668            278           1194           9558
           0.0025        33.9619      0.0205313            205           1314          10512
           0.0025        31.6869      0.0198829            183           1252          10021
           0.0025        36.7251       0.020879            445           1317          10523
           0.0025        30.9686      0.0197083            392           1243           9933
           0.0025         33.321      0.0201607            276           1271          10161
           0.0025        36.9575      0.0205456            304           1295          10355
           0.0025        32.1269      0.0188909            178           1190           9521
           0.0025        38.5598      0.0206523            308           1322          10574
           0.0025        40.3621      0.0206738            404           1323          10585
           0.0025        38.3179      0.0196074            438           1255          10039
           0.0025        37.1893      0.0202044            321           1273          10183
           0.0025        43.4816      0.0207734            380           1329          10636
           0.0025        31.8064      0.0200352            386           1281          10258
           0.0025        32.8692      0.0202056            187           1254          10022
           0.0025         34.287      0.0198427            282           1230           9842
           0.0025        31.4285      0.0205516            235           1293          10358
           0.0025        35.3737      0.0205437            338           1295          10354
           0.0027        42.4967      0.0215215            343           1379          11019
           0.0027        45.6406      0.0219844            380           1408          11256
           0.0027        41.5056      0.0218689            488           1333          10672
           0.0027        43.6342      0.0219727            385           1408          11250
           0.0027        46.1974      0.0223353            482           1408          11257
           0.0027        42.1278      0.0212734            625           1362          10892
           0.0027        43.4795      0.0217148            645           1389          11118
           0.0027        47.7298      0.0216738            578           1388          11097
           0.0027        41.2402      0.0219492            396           1403          11238
           0.0027        41.1503       0.021994            343           1364          10909
           0.0027        35.8235       0.021166            244           1354          10837
           0.0027        53.4215          0.023            479           1426          11408
           0.0027        51.9258      0.0230827            551           1429          11449
           0.0027         46.887      0.0223867            381           1433          11462
           0.0027        66.6257      0.0228867           1158           1464          11718
           0.0027        40.6989      0.0210254            431           1345          10765
           0.0027        43.8632      0.0222679            413           1403          11223
           0.0027        41.2715      0.0215898            383           1381          11054
           0.0027        47.1981      0.0217578            514           1393          11140
           0.0027        46.6527      0.0215504            579           1336          10689
           0.0029        68.7928      0.0236593            687           1467          11735
           0.0029        73.8114      0.0234023           1612           1495          11982
           0.0029        46.5185      0.0227812            364           1460          11664
           0.0029        66.7058      0.0238379            744           1526          12205
           0.0029        77.6965      0.0233789            698           1496          11970
           0.0029        71.2546      0.0243274           1029           1532          12261
           0.0029        75.7829      0.0235176            774           1506          12041
           0.0029        42.3764       0.022957            324           1469          11754
           0.0029        52.6266      0.0228652            625           1465          11707
           0.0029          61.31      0.0235476            595           1484          11868
           0.0029         45.142      0.0224551            491           1437          11497
           0.0029        138.621      0.0238652           2416           1529          12219
           0.0029        56.9513      0.0230762            501           1477          11815
           0.0029        77.5086       0.023668            851           1514          12118
           0.0029        58.4457      0.0225937            597           1445          11568
           0.0029        57.7615      0.0235655            543           1484          11877
           0.0029        96.0405      0.0235488           2068           1508          12057
           0.0029        49.7371      0.0230504            405           1430          11433
           0.0029        68.6692      0.0222402            875           1424          11387
           0.0029        98.9432      0.0243333           1248           1532          12264
           0.0031        72.6287       0.024244            713           1527          12219
           0.0031        74.0257      0.0243711           1028           1558          12478
           0.0031        62.1552       0.024834            624           1591          12715
           0.0031        105.022      0.0247718           1181           1561          12485
           0.0031        97.1323      0.0245703           1455           1572          12580
           0.0031        86.8299      0.0249629           1068           1599          12781
           0.0031        78.0381      0.0242305           1049           1549          12406
           0.0031        73.9762       0.024957            849           1598          12778
           0.0031        105.899      0.0240586           1444           1540          12318
           0.0031        92.3766      0.0248945           1432           1593          12746
           0.0031        128.163      0.0251563           1753           1611          12880
           0.0031        78.5597      0.0249961            587           1601          12798
           0.0031        119.205      0.0249147           1661           1569          12557
           0.0031        103.028      0.0255645            797           1637          13089
           0.0031        164.118      0.0254766           2331           1631          13044
           0.0031        74.1075      0.0248254            793           1563          12512
           0.0031        286.934      0.0250215           4318           1603          12811
           0.0031        168.787      0.0257402           1992           1648          13179
           0.0031        77.3798      0.0250988           1145           1556          12449
           0.0031        84.0469      0.0246348           1028           1577          12613
           0.0033        124.616      0.0261699           1088           1673          13399
           0.0033          143.8      0.0264805           2363           1694          13558
           0.0033        271.294      0.0253984           3600           1626          13004
           0.0033        149.704      0.0255879           1525           1637          13101
           0.0033        155.365      0.0264727           1848           1694          13554
           0.0033        223.422      0.0266738           2328           1708          13657
           0.0033        82.4236       0.026084            797           1669          13355
           0.0033        426.759      0.0260323           4201           1615          12912
           0.0033        283.298      0.0253945           5747           1625          13002
           0.0033        303.717      0.0262282           3386           1653          13219
           0.0033        511.343      0.0254214           5696           1576          12609
           0.0033         230.48      0.0256074           4189           1640          13111
           0.0033        212.632      0.0256445           3397           1640          13130
           0.0033        112.812      0.0253691           2328           1624          12989
           0.0033        139.424      0.0265714           1327           1674          13392
           0.0033          249.1      0.0255293           3891           1634          13071
           0.0033        235.729      0.0258452           2680           1628          13026
           0.0033        176.415      0.0254238           1817           1628          13017
           0.0033        117.548      0.0256562           2024           1643          13136
           0.0033        467.686      0.0261523           5041           1674          13390
];

rows = size(data, 1);
cols = size(data, 2);

data_delay = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+1);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_delay = [data_delay; data(ifirst, 1:cols-5), avg ci];
end

figure(1);
hold on;
plot(data_delay(:,1), data_delay(:,2), symbol);

data_throughput = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+2);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_throughput = [data_throughput; data(ifirst, 1:cols-5), avg ci];
end

figure(2);
hold on;
plot(data_throughput(:,1), data_throughput(:,2), symbol);

data_maxdelay = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+3);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_maxdelay = [data_maxdelay; data(ifirst, 1:cols-5), avg ci];
end

figure(3);
hold on;
plot(data_maxdelay(:,1), data_maxdelay(:,2), symbol);


%-------- Saturation Analysis -----------
slope=[];
for i=2:size(data_throughput,1),
    slope(i-1) = (data_throughput(i,2)-data_throughput(i-1,2))/(data_throughput(i,1)-data_throughput(i-1,1));
end

for i=2:size(slope,2),
    if slope(i) < (0.95*mean(slope(1:i)))
        max_pir = data_throughput(i, 1);
        max_throughput = data_throughput(i, 2);
        min_delay = data_delay(i, 2);
        break;
    end
end
